﻿using System;
using System.Drawing;

namespace TileGert
{
  /// <summary>
  /// GertMisc is a collection of several tool methods.
  /// </summary>
  internal class GertMisc
  {
    private GertMisc()
    {
    }
    
    /// <summary>
    /// Converta a System.Drawing.Color to an int for usage with Direct3D.
    /// </summary>
    /// <param name="color"></param>
    /// <returns></returns>
    public static int ColorToInt(Color color)
    {
      int a = color.A;
      int r = color.R;
      int g = color.G;
      int b = color.B;
      
      a = a << 24;
      r = r << 16;
      g = g << 8;
      
      int result = a | r | g | b;
      return result;
    }
    
    /// <summary>
    /// Calculates the bigger of the two int's.
    /// </summary>
    /// <param name="v1">The first int.</param>
    /// <param name="v2">The second int.</param>
    /// <returns>The bigger of the two int's.</returns>
    public static int Max(int v1, int v2)
    {
      return v1 > v2 ? v1 : v2;
    }
    
    /// <summary>
    /// Calculates the smaller of the two int's.
    /// </summary>
    /// <param name="v1">The first int.</param>
    /// <param name="v2">The second int.</param>
    /// <returns>The smaller of the two int's.</returns>
    public static int Min(int v1, int v2)
    {
      return v1 < v2 ? v1 : v2;
    }

    /// <summary>
    /// Calculates the bigger of the two float's.
    /// </summary>
    /// <param name="v1">The first float.</param>
    /// <param name="v2">The second float.</param>
    /// <returns>The bigger of the two float's.</returns>
    public static float Max(float v1, float v2)
    {
      return v1 > v2 ? v1 : v2;
    }

    /// <summary>
    /// Calculates the smaller of the two float's.
    /// </summary>
    /// <param name="v1">The first float.</param>
    /// <param name="v2">The second float.</param>
    /// <returns>The smaller of the two float's.</returns>
    public static float Min(float v1, float v2)
    {
      return v1 < v2 ? v1 : v2;
    }
    
    /// <summary>
    /// Clamps the given value to the range defined by min and max.
    /// </summary>
    /// <param name="value">The value to be clamped.</param>
    /// <param name="min">The minimum value.</param>
    /// <param name="max">The maximum value.</param>
    /// <returns>The clamped value.</returns>
    public static int Clamp(int value, int min, int max)
    {
      return value > max ? max : value < min ? min : value;
    }
    
  }
}
